<%@page import="models.Lesson"%>
<%@page import="java.util.List"%>
<%@page import="dao.LessonDao"%>
<%@page import="classes.HibernateUtil"%>
<%@include file="../template/configuration.jsp" %>
<%
if (request.getParameter("course_id") != null && request.getParameter("page") != null) {
    HibernateUtil hu = new HibernateUtil();
    LessonDao cd = new LessonDao(hu.openSession());
    List<Lesson> lessons = cd.getPagination(Long.parseLong(request.getParameter("course_id")), Integer.parseInt(request.getParameter("page")));
    pageContext.setAttribute("lessonList", lessons);
}
%>
<table id="search-table" class="overview">
    <thead>
        <tr>
            <th>Name</th>
            <th>Description</th>
            <th>Course</th>
            <th class="date">Added</th>
            <th class="manage-large">Manage</th>
        </tr>
    </thead>
    <tbody>
        <c:set var="i" value="0"/>
        <c:forEach items="${lessonList}" var="Lessons">
                <c:set var="i" value="${i + 1}"/>
                <tr class="<c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                    <td>
                        ${Lessons.name}
                    </td>
                    <td>
                        ${Lessons.description}
                    </td>
                    <td>
                        ${Lessons.course.name}
                    </td>
                    <td> 
                        ${Lessons.date}
                    </td>
                    <td>
                        <a href="${url}Lesson?id=${Lessons.id}"><img src="${url}images/edit.png"/></a>
                        <a href="${url}FileController/view?id=${Lessons.id}"><img src="${url}images/add-file.png"/></a>
                        <a href="${url}Lesson?idremove=${Lessons.id}" class="remove"><img src="${url}images/remove.png"/></a>                            
                        <span class="info">Lesson <strong>${Lessons.name}</strong></span>
                    </td>                                        
                </tr>
        </c:forEach> 
    </tbody>
</table>